//
//  AOVisitorController.swift
//  weibo_zha
//
//  Created by _zha on 16/10/24.
//  Copyright © 2016年 渣. All rights reserved.
//

import UIKit

class AOVisitorController: UIViewController {

    //判断用户是否登录的标示
    var isLogin: Bool = AOUserAccountViewModel.sharedTools.isLogin
    //访客视图
    var visitorView: AOVisitorView?
    
    override func loadView() {
        // 登录了
        if isLogin {
            view = tableView
        }else {
            // 代表没有登录
            setupVisitorView()
        }
    }
    
    //设置访客视图
    private func setupVisitorView(){
        // 创建访客视图
        visitorView = AOVisitorView()
        
        visitorView?.closure = {[weak self] in
            //闭包的回调
            self?.loginClick()
        }
        view = visitorView
        
        setupNav()
    }
    
    //设置导航
    private func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(setHighlightedImgName: nil, title: "注册", target: self, action: #selector(loginClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(setHighlightedImgName: nil, title: "登录", target: self, action: #selector(loginClick))
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    //监听事件
    @objc private func loginClick(){
        //未来弹出微博登录控制器
        //        print("访客视图四个按钮点击")
        let oauthVc = AOOAuthController()
        let oauthNavC = AONavigationController(rootViewController: oauthVc)
        present(oauthNavC, animated: true, completion:  nil)
    }
    
    //懒加载控件
    lazy var tableView: UITableView = UITableView()


}
